import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import echarts from "echarts";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import "./assets/styles/reset.css";
import 'swiper/dist/css/swiper.min.css'
import 'swiper/dist/js/swiper.min'
import less from "less";
Vue.use(less);
Vue.use(ElementUI);
Vue.config.productionTip = false;
Vue.prototype.$echarts = echarts;

router.beforeEach((to, from, next) => {
  if (to.matched.some((record) => record.meta.requireAuth)) {
    // 判断该路由是否需要登录权限
    if (sessionStorage.getItem("token")) {
      // 判断当前的token是否存在
      next();
    } else {
      next({
        path: "/login",
        query: { redirect: to.fullPath }, // 将跳转的路由path作为参数，登录成功后跳转到该路由
      });
    }
  } else {
    next();
  }
});

const appDev = new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
window.$message = appDev.$message;
window.$globalUrl = 'http://project.tingyun.work:32784';